package com.bootdo.mq;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Queue;
import org.springframework.stereotype.Service;

import com.bootdo.common.config.ApplicationContextRegister;
import com.bootdo.payee.domain.PayeeDO;

/**
 * @program: bootdo
 * @packageName: com.bootdo.mq
 * @className: InitQueueBeforeStartTask
 * @description: InitQueueBeforeStartTask
 * @author: Silver2018
 * @create: 2020-03-17 10:41
 */
@Service
public class InitQueueBeforeStartTask implements Runnable {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private List<PayeeDO> list;

    private RabbitUtil rabbitUtil;

    public InitQueueBeforeStartTask(){

    }
    public InitQueueBeforeStartTask(List<PayeeDO> list){
        rabbitUtil= ApplicationContextRegister.getBean(RabbitUtil.class);
        this.list = list;
    }

    @Override
    public void run() {
        makeQueue(list);
    }

    private void makeQueue(List<PayeeDO> list){
        for (PayeeDO payee: list) {
            String queueName = "topic.payee.user_"+payee.getUserId();
            Queue queue = new Queue(queueName,true);
            rabbitUtil.addQueue(queue);
            logger.debug("创建队列成功："+queueName);
        }
    }
}
